﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
using System.ComponentModel;
using System.IO;

namespace ClockwiseClient
{
    public class ClassStockData : ClassStock
    {
        BackgroundWorker worker = null;
        string strShFilName = null;
        string strSzFilName = null;
        List<ClassStockItem> lstClassStockItem = null;
        List<ClassStockItem> lstClassIndexItem = null;
        ClassFilterZhongGuo classFilterZhongGuo = null;
        ClassFilterBaoZi classFilterBaoZi = null;
        ClassFilterHaoHan classFilterHaoHan = null;
        ClassFilterHouGu classFilterHouGu = null;
        ClassFilterZiXuan classFilterZiXuan = null;
        ClassFilterHistory classFilterHistory = null;
        ClassFilterAG classFilterAG = null;
        ClassFilterBG classFilterBG = null;
        ClassFilterSzb classFilterSzb = null;
        ClassFilterHzb classFilterHzb = null;
        ClassFilterCyb classFilterCyb = null;
        ClassFilterKcb classFilterKcb = null;
        ClassFilterZxb classFilterZxb = null;
        ClassFilterST classFilterST = null;
        ClassFilterJiJin classFilterJiJin = null;
        ClassFilterZhiShu classFilterZhiShu = null;
        ClassFilterOther classFilterOther = null;
        EnumFilter filter = EnumFilter.FILTER_AG;
        EnumSorter sorter = EnumSorter.SORTER_INVALID;
        public ClassStockLabel classStockLabel = null;
        public int boardStockIdx = -1;
        public int focusStockIdx = 0;
        List<ClassStockDays> lstClassStockDays = null;
        List<ClassStockTick> lstClassStockTick = null;

        public void LoadStockInfo() 
        {
            strShFilName = ClassStock.strWorkDir + "\\wShInfo.txt";
            strSzFilName = ClassStock.strWorkDir + "\\wSzInfo.txt";
            if (worker == null)
            {
                worker = new BackgroundWorker();
                worker.DoWork += DoWork;
                worker.WorkerReportsProgress = true;
                worker.WorkerSupportsCancellation = true;
                worker.ProgressChanged += ProgressChanged;
                worker.RunWorkerAsync();
            }
        }

        void DoWork(object sender, DoWorkEventArgs e)
        {
            lstClassStockItem = new List<ClassStockItem>();
            lstClassIndexItem = new List<ClassStockItem>();
            classStockLabel = new ClassStockLabel();
            classFilterZhongGuo = new ClassFilterZhongGuo();
            classFilterBaoZi = new ClassFilterBaoZi();
            classFilterHaoHan = new ClassFilterHaoHan();
            classFilterHouGu = new ClassFilterHouGu();
            classFilterZiXuan = new ClassFilterZiXuan();
            classFilterHistory = new ClassFilterHistory();
            classFilterAG = new ClassFilterAG();
            classFilterBG = new ClassFilterBG();
            classFilterSzb = new ClassFilterSzb();
            classFilterHzb = new ClassFilterHzb();
            classFilterCyb = new ClassFilterCyb();
            classFilterKcb = new ClassFilterKcb();
            classFilterZxb = new ClassFilterZxb();
            classFilterST = new ClassFilterST();
            classFilterJiJin = new ClassFilterJiJin();
            classFilterZhiShu = new ClassFilterZhiShu();
            classFilterOther = new ClassFilterOther();
            int i, idx = 0;
            for (i = 0; i < 4; i++)
            {
                ClassStockItem item = new ClassStockItem();
                switch(i)
                {
                    case 0:
                        item.symbol = ".1";
                        item.code = "108";
                        item.name = "好汉指数";
                        break;
                    case 1:
                        item.symbol = ".2";
                        item.code = "888";
                        item.name = "猴股指数";
                        break;
                    case 2:
                        item.symbol = ".3";
                        item.code = "999999";
                        item.name = "上证综指";
                        break;
                    case 3:
                        item.symbol = ".4";
                        item.code = "399999";
                        item.name = "深证成指";
                        break;
                }
                lstClassIndexItem.Add(item);
            }
            for (i = 0; i < 2; i++)
            {
                int percent;
                try
                {
                    worker.ReportProgress(0, i == 1 ? "沪股" : "深股");
                    FileInfo fi = new FileInfo(i == 0 ? strShFilName : strSzFilName);
                    StreamReader sr = new StreamReader(i == 1 ? strShFilName : strSzFilName);
                    Stream s = sr.BaseStream;
                    while (true)
                    {
                        string str = sr.ReadLine();
                        if (str == null || str.Length < 1) break;
                        ClassStockItem classStockItem = new ClassStockItem();
                        int k = 0;
                        bool accept = false;
                        while (true)
                        {
                            int j = str.IndexOf(',');
                            if (j < 0)
                            {
                                classStockItem.f_delta = classStockItem.f_volume;
                                float zgj = float.Parse(classStockItem.high);
                                float zdj = float.Parse(classStockItem.low);
                                float zf = 0;
                                if (zgj > 0 && zdj > 0) zf = (zgj - zdj) * 100 / zdj;
                                classStockItem.f_amplitude = zf;
                                lstClassStockItem.Add(classStockItem);
                                break;
                            }
                            switch (k)
                            {
                                case 0:
                                    classStockItem.symbol = str.Substring(0, j);
                                    if (classFilterAG.Accept(idx, classStockItem.symbol)) accept = true;
                                    if (classFilterBG.Accept(idx, classStockItem.symbol)) accept = true;
                                    classFilterSzb.Accept(idx, classStockItem.symbol);
                                    classFilterHzb.Accept(idx, classStockItem.symbol);
                                    classFilterCyb.Accept(idx, classStockItem.symbol);
                                    classFilterKcb.Accept(idx, classStockItem.symbol);
                                    classFilterZxb.Accept(idx, classStockItem.symbol);
                                    classFilterHaoHan.Accept(idx, classStockItem.symbol);
                                    classFilterHouGu.Accept(idx, classStockItem.symbol);
                                    classFilterZiXuan.Accept(idx, classStockItem.symbol);
                                    classFilterHistory.Accept(idx, classStockItem.symbol);
                                    if (classFilterJiJin.Accept(idx, classStockItem.symbol)) accept = true;
                                    if (classFilterZhiShu.Accept(idx, classStockItem.symbol)) accept = true;
                                    if (!accept) classFilterOther.Accept(idx, classStockItem.symbol);
                                    break;
                                case 1:
                                    classStockItem.name = str.Substring(0, j);
                                    classFilterZhongGuo.Accept(idx, classStockItem.name);
                                    classFilterST.Accept(idx, classStockItem.name);
                                    break;
                                case 2:
                                    classStockItem.trade = str.Substring(0, j);
                                    break;
                                case 3:
                                    classStockItem.pricechange = str.Substring(0, j);
                                    break;
                                case 4:
                                    classStockItem.changepercent = str.Substring(0, j);
                                    break;
                                case 5:
                                    classStockItem.buy = str.Substring(0, j);
                                    break;
                                case 6:
                                    classStockItem.sell = str.Substring(0, j);
                                    break;
                                case 7:
                                    classStockItem.settlement = str.Substring(0, j);
                                    break;
                                case 8:
                                    classStockItem.open = str.Substring(0, j);
                                    break;
                                case 9:
                                    classStockItem.high = str.Substring(0, j);
                                    break;
                                case 10:
                                    classStockItem.low = str.Substring(0, j);
                                    break;
                                case 11:
                                    classStockItem.volume = str.Substring(0, j);
                                    break;
                                case 12:
                                    classStockItem.amount = str.Substring(0, j);
                                    break;
                                case 13:
                                    classStockItem.code = str.Substring(0, j);
                                    classFilterBaoZi.Accept(idx, classStockItem.code);
                                    break;
                                case 14:
                                    classStockItem.ticktime = str.Substring(0, j);
                                    break;
                            }
                            str = str.Substring(j + 1);
                            k++;
                        }
                        percent = (int)(s.Position * 100 / s.Length);
                        if (percent > 100) percent = 100;
                        worker.ReportProgress(percent, string.Format("{0}%", percent));
                        idx++;
                        // Thread.Sleep(1);
                    }
                    sr.Close();
                    Thread.Sleep(500);
                    continue;
                }
                catch (Exception)
                {
                    // MessageBox.Show(ex.Message);
                }
                for(int j = 0; j < 15; j++)
                {
                    int pos = -1;
                    bool isFileOpened = false;
                    try
                    {
                        FileStream fsInfo = null;
                        if (i == 0)
                        {
                            ClassStock.strSzWorkDir = ClassStock.strWorkDir + @"\" + DateTime.Now.AddDays(0 - j).ToString(@"yyyyMMdd");
                            strSzFilName = ClassStock.strSzWorkDir + @"\wSzInfo.dat";
                            fsInfo = new FileStream(strSzFilName, FileMode.Open);
                        }
                        if (i == 1)
                        {
                            ClassStock.strShWorkDir = ClassStock.strWorkDir + @"\" + DateTime.Now.AddDays(0 - j).ToString(@"yyyyMMdd");
                            strShFilName = ClassStock.strShWorkDir + @"\wShInfo.dat";
                            fsInfo = new FileStream(strShFilName, FileMode.Open);
                        }
                        isFileOpened = true;
                        lstClassStockDays = new List<ClassStockDays>();
                        const int stockDataSize = 256;
                        byte[] buff = new byte[stockDataSize];
                        int Count = (int)(fsInfo.Length / buff.Length), len;
                        for (int k = 0; k < Count; k++)
                        {
                            fsInfo.Read(buff, 0, buff.Length);
                            bool accept = false;
                            ClassStockItem classStockItem = new ClassStockItem();
                            len = 0; pos = stockDataSize - 8; while (pos < stockDataSize) { if (buff[pos] == 0) break; pos++; len++; }
                            classStockItem.code = System.Text.Encoding.ASCII.GetString(buff, stockDataSize - 8, len);
                            classFilterBaoZi.Accept(idx, classStockItem.code);
                            classStockItem.symbol = (i == 1 ? "sh" : "sz") + classStockItem.code;
                            if (classFilterAG.Accept(idx, classStockItem.symbol)) accept = true;
                            if (classFilterBG.Accept(idx, classStockItem.symbol)) accept = true;
                            classFilterSzb.Accept(idx, classStockItem.symbol);
                            classFilterHzb.Accept(idx, classStockItem.symbol);
                            classFilterCyb.Accept(idx, classStockItem.symbol);
                            classFilterKcb.Accept(idx, classStockItem.symbol);
                            classFilterZxb.Accept(idx, classStockItem.symbol);
                            classFilterHaoHan.Accept(idx, classStockItem.symbol);
                            classFilterHouGu.Accept(idx, classStockItem.symbol);
                            classFilterZiXuan.Accept(idx, classStockItem.symbol);
                            classFilterHistory.Accept(idx, classStockItem.symbol);
                            if (classFilterJiJin.Accept(idx, classStockItem.symbol)) accept = true;
                            if (classFilterZhiShu.Accept(idx, classStockItem.symbol)) accept = true;
                            if (!accept) classFilterOther.Accept(idx, classStockItem.symbol);
                            len = 0; pos = stockDataSize - 38; while (pos < stockDataSize - 8) { if (buff[pos] == 0) break; pos++; len++; }
                            classStockItem.name = System.Text.Encoding.UTF8.GetString(buff, stockDataSize - 38, len);
                            classFilterZhongGuo.Accept(idx, classStockItem.name);
                            classFilterST.Accept(idx, classStockItem.name);
                            pos = 0; classStockItem.f_time = BitConverter.ToSingle(buff, pos); 
                            pos += 4;classStockItem.f_price = BitConverter.ToSingle(buff, pos); 
                            pos += 4;classStockItem.f_diff = BitConverter.ToSingle(buff, pos); 
                            pos += 4;classStockItem.f_change = BitConverter.ToSingle(buff, pos); 
                            pos += 4;classStockItem.f_preclose = BitConverter.ToSingle(buff, pos); 
                            pos += 4;classStockItem.f_open = BitConverter.ToSingle(buff, pos); 
                            pos += 4;classStockItem.f_high = BitConverter.ToSingle(buff, pos); 
                            pos += 4;classStockItem.f_low = BitConverter.ToSingle(buff, pos); 
                            pos += 4;classStockItem.f_amplitude = BitConverter.ToSingle(buff, pos); 
                            pos += 4;classStockItem.f_volume = BitConverter.ToSingle(buff, pos); 
                            pos += 4;classStockItem.f_amount = BitConverter.ToSingle(buff, pos); 
                            pos += 4;classStockItem.f_buy = BitConverter.ToSingle(buff, pos); 
                            pos += 4;classStockItem.f_sell = BitConverter.ToSingle(buff, pos); 
                            pos += 4;classStockItem.f_delta = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_buy2 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_buy3 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_buy4 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_buy5 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_sell2 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_sell3 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_sell4 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_sell5 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_buyV = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_buyV2 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_buyV3 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_buyV4 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_buyV5 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_sellV = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_sellV2 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_sellV3 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_sellV4 = BitConverter.ToSingle(buff, pos);
                            pos += 4; classStockItem.f_sellV5 = BitConverter.ToSingle(buff, pos);
                            classStockItem.trade = classStockItem.f_price.ToString("f2");
                            classStockItem.pricechange = classStockItem.f_diff.ToString("f2");
                            classStockItem.changepercent = classStockItem.f_change.ToString("f2");
                            classStockItem.settlement = classStockItem.f_preclose.ToString("f2");
                            classStockItem.buy = classStockItem.f_buy.ToString("f2");
                            classStockItem.sell = classStockItem.f_sell.ToString("f2");
                            classStockItem.open = classStockItem.f_open.ToString("f2");
                            classStockItem.high = classStockItem.f_high.ToString("f2");
                            classStockItem.low = classStockItem.f_low.ToString("f2");
                            classStockItem.volume = classStockItem.f_volume.ToString("f0");
                            classStockItem.amount = classStockItem.f_amount.ToString("f0");
                            lstClassStockItem.Add(classStockItem);
                            ClassStockDays classStockDays = new ClassStockDays();
                            classStockDays.LoadStockDays(i, classStockItem.code);
                            lstClassStockDays.Add(classStockDays);
                            percent = (int)(k * 100 / Count);
                            if (percent > 100) percent = 100;
                            worker.ReportProgress(percent, string.Format("{0}%", percent));
                            idx++;
                            // Thread.Sleep(1);
                        }
                        fsInfo.Close();
                        Thread.Sleep(500);
                        break;
                    }
                    catch (Exception ex)
                    {
                        if(isFileOpened) MessageBox.Show(ex.Message + ", pos:" + pos);
                        if(j == 14) MessageBox.Show((i == 1 ? "沪" : "深") + "股无最近十五天的数据");
                    }
                }
            }
            worker.ReportProgress(100, "OVER");
            worker.CancelAsync();
            worker = null;
            strShFilName = null;
            strSzFilName = null;
        }

        FormLogin formLogin = null;

        public ClassStockData SetFormLogin(FormLogin form)
        {
            formLogin = (FormLogin)form;
            return this;
        }

        void ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            formLogin.SetValue(e.ProgressPercentage);
            string message = e.UserState.ToString();
            if (!message.Equals("OVER"))
                formLogin.SetText(message);
            else
                formLogin.Hidden();
        }

        public int GetAgCount() { return classFilterAG.GetCount(); }
        public int GetBgCount() { return classFilterBG.GetCount(); }
        public int GetSzbCount() { return classFilterSzb.GetCount(); }
        public int GetHzbCount() { return classFilterHzb.GetCount(); }
        public int GetCybCount() { return classFilterCyb.GetCount(); }
        public int GetKcbCount() { return classFilterKcb.GetCount(); }
        public int GetZxbCount() { return classFilterZxb.GetCount(); }
        public int GetStCount() { return classFilterST.GetCount(); }
        public int GetJjCount() { return classFilterJiJin.GetCount(); }
        public int GetZsCount() { return classFilterZhiShu.GetCount(); }
        public int GetQtCount() { return classFilterOther.GetCount(); }
        public int GetZhongguoCount() { return classFilterZhongGuo.GetCount(); }
        public int GetBaoziCount() { return classFilterBaoZi.GetCount(); }
        public int GetHaohanCount() { return classFilterHaoHan.GetCount(); }
        public int GetHouguCount() { return classFilterHouGu.GetCount(); }
        public int GetZixuanCount() { return classFilterZiXuan.GetCount(); }

        public void SetFilter(EnumFilter filter)
        {
            this.filter = filter;
        }

        public ClassFilter GetFilter()
        {
            ClassFilter classFilter = null;
            switch (filter)
            {
                case EnumFilter.FILTER_ZHONGGUO:
                    classFilter = (ClassFilter)classFilterZhongGuo;
                    break;
                case EnumFilter.FILTER_BAOZI:
                    classFilter = (ClassFilter)classFilterBaoZi;
                    break;
                case EnumFilter.FILTER_HAOHAN:
                    classFilter = (ClassFilter)classFilterHaoHan;
                    break;
                case EnumFilter.FILTER_HOUGU:
                    classFilter = (ClassFilter)classFilterHouGu;
                    break;
                case EnumFilter.FILTER_ZIXUAN:
                    classFilter = (ClassFilter)classFilterZiXuan;
                    break;
                case EnumFilter.FILTER_HISTORY:
                    classFilter = (ClassFilter)classFilterHistory;
                    break;
                case EnumFilter.FILTER_AG:
                    classFilter = (ClassFilter)classFilterAG;
                    break;
                case EnumFilter.FILTER_BG:
                    classFilter = (ClassFilter)classFilterBG;
                    break;
                case EnumFilter.FILTER_SZB:
                    classFilter = (ClassFilter)classFilterSzb;
                    break;
                case EnumFilter.FILTER_HZB:
                    classFilter = (ClassFilter)classFilterHzb;
                    break;
                case EnumFilter.FILTER_CYB:
                    classFilter = (ClassFilter)classFilterCyb;
                    break;
                case EnumFilter.FILTER_KCB:
                    classFilter = (ClassFilter)classFilterKcb;
                    break;
                case EnumFilter.FILTER_ZXB:
                    classFilter = (ClassFilter)classFilterZxb;
                    break;
                case EnumFilter.FILTER_ST:
                    classFilter = (ClassFilter)classFilterST;
                    break;
                case EnumFilter.FILTER_JJ:
                    classFilter = (ClassFilter)classFilterJiJin;
                    break;
                case EnumFilter.FILTER_ZS:
                    classFilter = (ClassFilter)classFilterZhiShu;
                    break;
                case EnumFilter.FILTER_QT:
                    classFilter = (ClassFilter)classFilterOther;
                    break;
            }
            return classFilter;
        }

        public ClassStockItem GetClassIndexItem(int type)
        {
            int idx = type - 1;
            if (idx >= 0 && idx < lstClassIndexItem.Count)
            {
                return lstClassIndexItem[idx];
            }
            return null;
        }

        public ClassStockItem GetClassStockItem(int idx)
        {
            if (idx >= 0 && idx < lstClassStockItem.Count)
            {
                return lstClassStockItem[idx];
            }
            return null;
        }

        public List<String> LoadCodeName(String key)
        {
            int len = key.Length;
            bool find_dot = key.Substring(0, 1) == ".";
            List<String> lstCodeName = new List<String>();
            int i = 0;
            foreach (ClassStockItem classIndexItem in lstClassIndexItem)
            {
                if (find_dot)
                {
                    if (len < classIndexItem.symbol.Length)
                    {
                        String tmp = classIndexItem.symbol.Substring(0, len);
                        if (key.Equals(tmp))
                        {
                            lstCodeName.Add(classIndexItem.symbol + " " + classIndexItem.name);
                        }
                    }
                } else
                if (len < classIndexItem.code.Length && key.Equals(classIndexItem.code.Substring(0, len)))
                {
                    lstCodeName.Add(classIndexItem.code + " " + classIndexItem.name);
                }
            }
            foreach (ClassStockItem classStockItem in lstClassStockItem)
            {
                if (len == 0 || len <= 6 && key.Equals(classStockItem.code.Substring(0, len)))
                {
                    lstCodeName.Add(classStockItem.code + " " + classStockItem.name);
                    if (++i >= 100) break;
                }
            }
            return lstCodeName;
        }

        public int GetBoardStockIdx(String code)
        {
            int i = 0;
            boardStockIdx = -1;
            foreach (ClassStockItem classStockItem in lstClassStockItem)
            {
                if (code.Equals(classStockItem.code))
                {
                    boardStockIdx = i;
                    break;
                }
                i ++;
            }
            return boardStockIdx;
        }

        public int GetBoardStockIdx()
        {
            return boardStockIdx;
        }

        public void ClearBoardStockIdx()
        {
            boardStockIdx = -1;
        }

        public int GetCount()
        {
            return lstClassStockItem.Count;
        }

        public void SetSorter(EnumSorter sorter)
        {
            this.sorter = sorter;
        }

        public string GetCode(int position)
        {
            return lstClassStockItem[position].code;
        }
        public string GetName(int position)
        {
            return lstClassStockItem[position].name;
        }

        public float GetPrice(int position)
        {
            return lstClassStockItem[position].f_price;
        }

        public float GetDiff(int position)
        {
            return lstClassStockItem[position].f_diff;
        }

        public float GetChange(int position)
        {
            return lstClassStockItem[position].f_change;
        }

        public float GetBuy(int position)
        {
            return lstClassStockItem[position].f_buy;
        }

        public float GetSell(int position)
        {
            return lstClassStockItem[position].f_sell;
        }

        public float GetDelta(int position)
        {
            return lstClassStockItem[position].f_delta;
        }

        public float GetVolume(int position)
        {
            return lstClassStockItem[position].f_volume;
        }

        public float GetAmount(int position)
        {
            return lstClassStockItem[position].f_amount;
        }

        public float GetPreclose(int position)
        {
            return lstClassStockItem[position].f_preclose;
        }

        public float GetOpen(int position)
        {
            return lstClassStockItem[position].f_open;
        }

        public float GetHigh(int position)
        {
            return lstClassStockItem[position].f_high;
        }

        public float GetLow(int position)
        {
            return lstClassStockItem[position].f_low;
        }

        public float GetAmplitude(int position)
        {
            return lstClassStockItem[position].f_amplitude;
        }

        public void LoadStockTick(int market, string code, int idx = 0)
        {
            if (lstClassStockTick == null) lstClassStockTick = new List<ClassStockTick>();
            ClassStockTick classStockTick;
            if (lstClassStockTick.Count <= idx)
            {
                classStockTick = new ClassStockTick();
                lstClassStockTick.Add(classStockTick);
            }
            classStockTick = lstClassStockTick[idx];
            classStockTick.LoadStockTick(market, code);
        }

        public ClassStockTick LoadStockTick(int idx)
        {
            if(lstClassStockTick != null && idx < lstClassStockTick.Count)
            {
                return lstClassStockTick[idx];
            }
            return null;
        }

        public ClassStockDays findStockDays(string symbol)
        {
            if(lstClassStockDays != null)
            {
                foreach(ClassStockDays days in lstClassStockDays)
                {
                    ClassStockDays ret = days.findStockDays(symbol);
                    if (ret != null) return ret;
                }
            }
            return null;
        }

        public bool ZixuanguInclude(string symbol)
        {
            return classFilterZiXuan.Include(symbol);
        }

        public void AddToHistory(string symbol)
        {
            classFilterHistory.Upadate(symbol, lstClassStockItem);
        }

        public void AddToZixuangu(string symbol)
        {
            classFilterZiXuan.Update(symbol, lstClassStockItem);
        }

    }

    public class ClassStockLabel
    {
        const string serial = "序号";
        const string code = "代码";
        const string name = "名称";
        const string price = "最新价";
        const string diff = "涨跌值";
        const string change = "涨跌幅%";
        const string preclose = "昨收盘";
        const string buy = "叫买价";
        const string sell = "叫卖价";
        const string delta = "现量";
        const string volume = "成交量";
        const string open = "今开盘";
        const string high = "最高价";
        const string low = "最低价";
        const string amplitude = "振幅%";
        const string uplimit = "涨停";
        const string downlimit = "跌停";
        const string amount = "成交额";
        const string ticktime = "交易时间";

        private const int labelCount = 18;

        public int GetLabelCount()
        {
            return labelCount;
        }

        public string GetLabelName(int idx)
        {
            switch (idx)
            {
                case 0: return serial;
                case 1: return code;
                case 2: return name;
                case 3: return price;
                case 4: return change;
                case 5: return diff;
                case 6: return preclose;
                case 7: return buy;
                case 8: return sell;
                case 9: return delta;
                case 10: return volume;
                case 11: return open;
                case 12: return high;
                case 13: return low;
                case 14: return amplitude;
                case 15: return uplimit;
                case 16: return downlimit;
                case 17: return amount;
            }
            return "";
        }

        public int GetLabelWidth(int idx)
        {
            switch (idx)
            {
                case 0: return 4;
                case 1: return 6;
                case 2: return 8;
                case 16: return 8;
                case 17: return 8;
            }
            return 7;
        }
    }

    public class ClassStockItem
    {
        public string symbol;
        public string name;
        public string trade;
        public string pricechange;
        public string changepercent;
        public string buy;
        public string sell;
        public string settlement;
        public string open;
        public string high;
        public string low;
        public string volume;
        public string amount;
        public string code;
        public string ticktime;
        public float f_time;
        public float f_price;
        public float f_change;
        public float f_diff;
        public float f_preclose;
        public float f_open;
        public float f_high;
        public float f_low;
        public float f_amplitude;
        public float f_volume;
        public float f_amount;
        public float f_buy;
        public float f_sell;
        public float f_delta;
        public float f_buy2;
        public float f_buy3;
        public float f_buy4;
        public float f_buy5;
        public float f_sell2;
        public float f_sell3;
        public float f_sell4;
        public float f_sell5;
        public float f_buyV;
        public float f_buyV2;
        public float f_buyV3;
        public float f_buyV4;
        public float f_buyV5;
        public float f_sellV;
        public float f_sellV2;
        public float f_sellV3;
        public float f_sellV4;
        public float f_sellV5;

        public string GetString()
        {
            return symbol + "," + name + "," + trade + "," + pricechange + "," + changepercent + "," + buy + "," + sell + "," + settlement + "," + open + "," + high + "," + low + "," + volume + "," + amount + "," + code + "," + ticktime;
        }
    }

}
